package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import org.springframework.ui.Model;
import org.apache.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresPermissions;

import ${package.parent}.${package.ModuleName}.entity.${table.entityName};
import ${package.parent}.${package.ModuleName}.service.${table.serviceName};

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
   private static Logger logger = Logger.getLogger(${table.controllerName}.class);

   @Resource
   private ${table.serviceName} service;


   @RequiresPermissions("${package.ModuleName}:view")
   @RequestMapping
   public String list(HttpServletRequest request, Model model, ${table.entityName} entory) {
     String id = request.getParameter("id");
     super.setPageContext(request);
     List<${table.entityName}> list = service.list();
     model.addAttribute("menus", list);
     model.addAttribute("page", getPage());
     return "zfmenu/list";
   }
   /**
   * 去新增页面
   *
   * @param id
   * @param model
   * @return
   */
   @RequiresPermissions("${package.ModuleName}:create")
   @RequestMapping(value = "/{id}/create", method = RequestMethod.GET)
   public String showUpdateForm(@PathVariable("id") Long id, Model model) throws Exception {
     ${table.entityName} entory = service.getById(id);
     model.addAttribute("entory", entory);
     model.addAttribute("op", "修改");
     return "${package.ModuleName}/edit";
   }
   /**
   * 更新
   * @param entory
   * @param redirectAttributes
   * @return
   */
   @RequiresPermissions("${package.ModuleName}:create")
   @RequestMapping(value = "/{id}/update", method = RequestMethod.POST)
   public String update(${table.entityName} entory, RedirectAttributes redirectAttributes, HttpServletRequest request) throws Exception {
     redirectAttributes.addFlashAttribute("resultMsg", "更新成功");
     service.updateById(entory);
     return "redirect:/${package.ModuleName}";
   }
   /**
   * 去修改页面
   *
   * @param id
   * @param model
   * @return
   */
   @RequiresPermissions("${package.ModuleName}:update")
   @RequestMapping(value = "/{id}/update", method = RequestMethod.GET)
   public String showUpdateForm(@PathVariable("id") Long id, Model model) throws Exception {
     ${table.entityName} entory = service.getById(id);
     model.addAttribute("entory", entory);
     model.addAttribute("op", "修改");
     return "${package.ModuleName}/edit";
   }
   /**
   * 更新
   * @param entory
   * @param redirectAttributes
   * @return
   */
   @RequiresPermissions("${package.ModuleName}:update")
   @RequestMapping(value = "/{id}/update", method = RequestMethod.POST)
   public String update(${table.entityName} entory, RedirectAttributes redirectAttributes, HttpServletRequest request) throws Exception {
     redirectAttributes.addFlashAttribute("resultMsg", "更新成功");
     service.updateById(entory);
     return "redirect:/${package.ModuleName}";
   }

   @RequiresPermissions("${package.ModuleName}:delete")
   @RequestMapping(value = "/{id}/delete", method = RequestMethod.GET)
   public String deleteMenu(@PathVariable("id") Long id, Model model) throws Exception {
     service.removeById(id);
     return "redirect:/${package.ModuleName}";
   }
}
</#if>
